/**
 * 登陆拦截器
 * @author yanwl 
 * @date 2014-08-27
 */
package com.chnbst.bstyun.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.chnbst.bstyun.core.common.SignUtil;
import com.chnbst.bstyun.model.pojo.User;

public class LoginInterceptor extends HandlerInterceptorAdapter{
	@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User)request.getSession().getAttribute("userInfo");
        if(user == null) {
        	String str = request.getQueryString();
        	if(SignUtil.isNotEmpty(str)) {
        		str = "?" + request.getQueryString();
        	}else {
        		str = "";
        	}
        	response.sendRedirect("/user/login?returnUrl="+request.getRequestURI() + str);
        	return false;
        }else {
        	return true;
        }
        
    }
 
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        super.postHandle(request, response, handler, modelAndView);
    }
}
